#include <iostream>
using namespace std;

class Person
{
public:
    Person()
    {
        cout << "Person构造函数\n";
    }
    virtual ~Person()
    {
        cout << "Person析构函数\n";
    }
    virtual void run()
    {
        cout << "Person run\n";
    }

public:
    int m_age;
};
class Student : public Person
{
public:
    Student()
    {
        cout << "Student 构造函数\n";
    }
    ~Student()
    {
        cout << "Student 析构函数\n";
    }
    void run()
    {
        cout << "Student run\n";
    }
    void study()
    {
        cout << "Student study\n";
    }

public:
    int m_score;
};
int main()
{
#if 0
    Person *p1 = new Student();
    p1->run();
    delete p1;
#endif
#if 0
    Student *stu = (Student *)new Person();
      stu->run();
    delete stu;
#endif
#if 0
    Person *p1 = new Student();
    Person *p2 = new Person();
    // Student *stu2 = p1;
    Student *stu1 = (Student *)p1;
    stu1->run();
#endif
    Person *p1 = new Student();
    p1->run();
    Person *p2 = new Person();
    Student *stu2 = dynamic_cast<Student *>(p2);/*安全检测：stu2的地址置空*/
#if 0
    Student *stu2 = (Student *)p2;
    /*踩内存，子类指针指向父类没有使用danamic_cast可能就会存在踩内存，访问子类的格式化就会*/
    stu2->m_score = 66;
#endif
    cout << stu2 << endl;
    Student *stu1 = dynamic_cast<Student *>(p1);
    stu1->run();
    stu2->run();
    return 0;
}